package dev.alm.meituanservice.controller;

import dev.alm.meituanservice.common.Result;
import dev.alm.meituanservice.entity.Category;
import dev.alm.meituanservice.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("category")
@CrossOrigin
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping("list")
    public Result getCategoryList() {
        List<Category> categoryList = categoryService.getCategoryList();
        Result r = new Result();
        r.setCode("200");
        r.setMessage("success");
        r.setData(categoryList);
        return r;
    }

    @PostMapping("add")
    public Result addCategory(@RequestBody Category category) {
        Category category1 = categoryService.addCategory(category);
        Result r = new Result();
        r.setCode("200");
        r.setMessage("success");
        r.setData(category1);
        return r;
    }
}
